<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS函数</title>
</head>
<body>
    
</body>
<script>
    //let arr = new Array(1,2,3,4);
    console.log("==========array============");
    
    let arr = [1,2,3,4];
    arr[10] = 50;
    console.log(arr[10]);
    console.log(arr[9]);
    arr[8] = 'a';

    console.log(arr);
    // arr.forEach(function(e){
    //     console.log(e);
    // })
    arr.forEach(e => {
        console.log(e);
        
    });
    console.log("==========string============");
    let str = ' heeello world ';
    console.log(str);
    //length
    console.log(str.length);
    //charAt
    console.log(str.charAt(1));
    //indexOf
    console.log(str.indexOf("ee"));//第一个遇到就停，返回两个两个找的第几位也就是1
    //trim
    let s = str.trim();//去除左右两侧空格
    console.log(s);
    //substring
    console.log(str.substring(0,5));//含头不含尾(从0开始（包括0）找5-0个元素)
    
    console.log("==========自定义对象============");
    let user = {
        name : "丁真",
        age : 18,
        gender : "male",
        /* penRen : function(){
            alert("我测你的吗");
        } */
       penRen(){
        alert("我测你的吗");
       }
    }
    alert(user.name);
    user.penRen();
    console.log("==========JSON对象============");
    let jsoner = '{"name":"丁真","age":"18","gender":"male","addr":["beijing","litang"]}';
    alert(jsoner.name);
    //JSON字符串转对象
     let obj = JSON.parse(jsoner);
     alert(obj.name);
    //对象转JSON字符串
     alert(JSON.stringify(obj));
     console.log("==========BOM对象============");
     window.alert("Hello BOM alert");
     let show = window.confirm("您确认删除吗？");
     window.alert(show);
     let i = 0;
     setInterval(function(){
        i++;
        console.log("该定时器已执行"+i+"次");
     },2000);
     setTimeout(function(){//是会先后执行的，先跳前面那些警告框，跳完才计时
        alert("你爹来咯");
     },3000)
</script>
</html>